package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: DishController
 * Package: com.sky.controller.admin
 * Description:菜品的controller层
 *
 * @Author: Zhang Peiyuan
 * @Create: 2024-12-18-17:34
 * @Version: v1.0
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {

    @Resource
    private DishService dishService;

    /**
     * 保存菜品
     * @param dishDTO
     * @return
     */
    @PostMapping()
    public Result saveDish(@RequestBody DishDTO dishDTO){
        dishService.saveDish(dishDTO);
        return Result.success();
    }

    /**
     * 分页查询菜品
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> queryDishPage(DishPageQueryDTO dishPageQueryDTO){
        return Result.success(dishService.queryDishPage(dishPageQueryDTO));
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping()
    public Result deleteDishBatch(@RequestParam List<Long> ids){
        dishService.deleteDishBatch(ids);
        return Result.success();
    }

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<DishVO> getDishById(@PathVariable Long id){
        return Result.success(dishService.getDishById(id));
    }

    /**
     * 更新菜品
     * @param dishDTO
     * @return
     */
    @PutMapping()
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDishWithFalvor(dishDTO);
        return Result.success();
    }

    /**
     * 查询菜品列表
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    public Result<List<Dish>> queryDishList(Long categoryId){
        return Result.success(dishService.queryDishList(categoryId));
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id){
        dishService.updateStatus(status, id);
        return Result.success();
    }

}
